//
//  PersonalTableViewController.m
//  Work
//
//  Created by Apple on 15/12/18.
//  Copyright © 2015年 mohekeji. All rights reserved.
//

#import "PersonalTableViewController.h"
#import "DenLuViewController.h"
#import "ZYQAssetPickerController.h"
@interface PersonalTableViewController ()<ZYQAssetPickerControllerDelegate,UINavigationControllerDelegate,UIPickerViewDelegate>
{
    ALAsset * asset;
    
}
@end

@implementation PersonalTableViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.backGround.hidden = YES;
    _dataSource = @[@"男",@"女"];
    //    [_imageVIew setImage:tempImg];
    // Uncomment the following line to preserve selection between /Users/liuzechao/Desktop/Work/Work/ZYQAssetPickerController.h:118:27: 'ALAsset' is deprecated: first deprecated in iOS 9.0 - Use PHAsset from the Photos framework insteadpresentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
//- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
//    
//}
//- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view{
//
//}
//- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
//
//}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row ==0) {
        [self addPicture];
    }
    if (indexPath.row ==1) {
        [self addAge];
    }
    if (indexPath.row ==3) {
        [self addAge];
    }
    if (indexPath.row ==4) {
        self.backGround.hidden = NO;
    }
}
-(void)assetPickerController:(ZYQAssetPickerController *)picker didFinishPickingAssets:(NSArray *)assets{
    _photoArr=assets;
    [self jie];
}

-(void)addPicture{
    ZYQAssetPickerController*picker=[[ZYQAssetPickerController alloc]init];
    picker.maximumNumberOfSelection=1;
    picker.assetsFilter=[ALAssetsFilter allPhotos];
    picker.showEmptyGroups=NO;
    picker.delegate=self;
    picker.selectionFilter=[NSPredicate predicateWithBlock:^BOOL(id  evaluatedObject, NSDictionary* bindings) {
        if ([[(ALAsset*)evaluatedObject valueForProperty:ALAssetPropertyType] isEqual:ALAssetTypeVideo]) {
            NSTimeInterval duration = [[(ALAsset*)evaluatedObject valueForProperty:ALAssetPropertyDuration] doubleValue];
            return duration >= 1;
        } else {
            return YES;
        }
    }];
    [self presentViewController:picker animated:YES completion:NULL];
}
- (void)jie{
    CALayer * lay = _imageVIew.layer;
    [lay setMasksToBounds:YES];
    [lay setCornerRadius:21.5];
    asset = _photoArr[0];
    UIImage *tempImg=[UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage];
    [_imageVIew setImage:tempImg];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)addAge {
     
}
- (IBAction)queRen:(id)sender {
    NSDate *pickerDate = [self.datePicker date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSDateFormatter * dateO = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    [dateO setDateFormat:@"yyyy"];
    NSString *dateString = [dateFormatter stringFromDate:pickerDate];
    NSString *dateString1 = [dateO stringFromDate:pickerDate];
//    NSDate *date = [dateFormatter dateFromString:dateString];
    self.dataString.text = dateString;
    int a = [dateString1 intValue];
    self.age.text = [NSString stringWithFormat:@"%d",2015-a+1];
    self.backGround.hidden = YES;
}
- (IBAction)quXiao:(id)sender {
    self.backGround.hidden = YES;
}
#pragma mark - Table view data source

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return 7;
//}
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//    return 1;
//}


//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"oneCell" forIndexPath:indexPath];
//    if (indexPath.row == 0) {
//       asset = _photoArr[0];
//    UIImage *tempImg=[UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage];
//    [_imageVIew setImage:tempImg];
// }
//    return cell;
//}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // Navigation logic may go here, for example:
    // Create the next view controller.
    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:<#@"Nib name"#> bundle:nil];
    
    // Pass the selected object to the new view controller.
    
    // Push the view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
